//导入
/**
 * 总路由于地址
 *  集成模块的地址
 * * */
import NProgress from 'nprogress';
import "@/assets/css/nprogress/nprogress.css";

import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router';
const routerHistory = createWebHashHistory(); //createWebHashHistory()带#号，不带#createWebHistory

import Main from "@/components/layout/Main.vue";
import user from "@/router/user"; //会员管理
import order from "@/router/order"; //会员管理
import goods from "@/router/goods"; //订单管理
const router = createRouter({
   history: routerHistory,  // history
   routes:[{
              path:"/",
              name:"index",
              redirect:"/user" //重定向url首页地址
            },{
            path:"/index",
            name: "indexDefalut",
            meta:{
                title: "会员中心"
            },
            component:()=>import("@/pages/index.vue")
           },
           {
            path: "/login",
            name: "login",
            meta: {
              title: "产品中心"
            },
            component: () => import("@/components/layout/login.vue")
           },
           { //分员服务
            path: "/user",
            name: "user",
            redirect:"/user/list", //指定当前服务--页面的主页
            component:Main,
            children:user
          },{ //订单服务
            path: "/order",
            name: "order",
            redirect:"/order/list", //指定当前服务--页面的主页
            component:Main,
            children:order
          },{ //订单服务
            path: "/goods",
            name: "goods",
            redirect:"/goods/list", //指定当前服务--页面的主页
            component:Main,
            children:goods
          },
          { 
            path: '/:pathMatch(.*)*', 
            name: 'not-found',
            component: ()=>import("@/components/layout/404.vue")  //404页面
            },
        ]
});


//处理登录信息
router.beforeEach(function(to, from, next) {
  NProgress.start(); // 设置加载进度条(开始..)
  if (!localStorage.getItem("authorization")) {
    //查看用户信息是否存在
    if (to.path !== "/login") {
      return next("/login");
    }
  }
  next();
});
router.afterEach(() => {
  NProgress.done(); // 设置加载进度条(结束..)
});


export default router;
